package _15_generics._15_10;

/**
 * 在类型参数上使用通配符的的情况， 如果参数列表中使用该类型参数，
 * 那么编译器就会禁止调用
 */
public class _02_Holder<T> {
    private T value;
    public  _02_Holder(){
    }
    public _02_Holder(T value){
        this.value = value;
    }
    public void set(T value){
        this.value = value;
    }
    public T get(){
        return value;
    }

    @Override
    public boolean equals(Object obj){
        return value.equals(obj);
    }

    public static void main(String[] args) {
        _02_Holder<Apple> apple = new _02_Holder(new Apple());
        Apple a = apple.get();
        apple.set(a);

        _02_Holder<? extends Fruit> fruit = apple;
        Fruit p = fruit.get();
        a = (Apple) fruit.get();
//        fruit.set(new Apple());
        try {
            Orange o = (Orange) fruit.get();
        }catch (Exception e){
            System.out.println(e);
        }
        System.out.println(fruit.equals(a));
    }
}
